package com.lanou.moving.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageRequest;
import com.lanou.moving.R;
import com.lanou.moving.entity.MusicThemeRoot;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by 梁树珍 on 15/10/31.
 */
public class MusicThemeAdapter extends BaseAdapter{
    private Context context;
    private List<MusicThemeRoot.DataEntity> entities;

    public MusicThemeAdapter(Context context, List<MusicThemeRoot.DataEntity> entities) {
        this.context = context;
        this.entities = entities;
    }

    @Override
    public int getCount() {
        return entities == null ? 0 : entities.size();
    }

    @Override
    public Object getItem(int position) {
        return entities == null ? null :entities.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.music_theme_listview_item, null);
            holder = new ViewHolder();
            holder.music_theme_img = (ImageView) convertView.findViewById(R.id.music_theme_img);
            holder.theme_album_name = (TextView) convertView.findViewById(R.id.theme_album_name);
            holder.theme_album_desc = (TextView) convertView.findViewById(R.id.theme_album_desc);
            holder.read_count = (TextView) convertView.findViewById(R.id.read_count);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.theme_album_name.setText(entities.get(position).getName());
        holder.theme_album_desc.setText(entities.get(position).getDesc());
        holder.read_count.setText(String.valueOf(entities.get(position).getClickCount()));
        Picasso.with(context).load(entities.get(position).getPicUrl()).into(holder.music_theme_img);
        return convertView;
    }
    public class ViewHolder{
        private ImageView music_theme_img;
        private TextView theme_album_name, theme_album_desc, read_count;
    }
}
